package com.share.common.security.utils.EntityAuditable;



import com.share.common.core.web.domain.BaseEntity;
import com.share.common.security.utils.SecurityUtils;

import java.util.Date;

// 通用实体工具类
public class EntityUtils {

    /**
     * 设置实体的创建信息和更新信息
     */
    public static <T extends EntityAuditable> void setCreateInfo(T entity) {
        String username = SecurityUtils.getUsername();
        Date now = new Date();
        
        entity.setCreateBy(username);
        entity.setCreateTime(now);
        entity.setUpdateTime(now);
    }
    
    /**
     * 仅设置实体的更新信息
     */
    public static <T extends EntityAuditable> void setUpdateInfo(T entity) {
        entity.setUpdateBy(SecurityUtils.getUsername());
        entity.setUpdateTime(new Date());
    }
}